package com.rzwl.single.server.entity;

import cn.binarywang.wx.miniapp.bean.WxMaUserInfo;
import lombok.Data;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import java.io.Serializable;
import java.sql.Timestamp;
import java.util.Objects;

@EntityListeners(AuditingEntityListener.class)
@Entity
@Table(name = "wx_user")
@Data
public class WxUser implements Serializable {

    private static final long serialVersionUID = -8366929034564774130L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    private String openid;
    private String unionid;
    private String nickName;
    private Integer gender;
    private String language;
    private String city;
    private String province;
    private String country;
    private String avatarUrl;
    @CreatedDate
    @Basic
    private Timestamp ctime;
    @LastModifiedDate
    @Basic
    private Timestamp utime;

    public boolean equalsToWxMaUserInfo(WxMaUserInfo o) {

        WxMaUserInfo user = (WxMaUserInfo) o;
        return Objects.equals(openid, user.getOpenId()) &&
                Objects.equals(unionid, user.getUnionId()) &&
                Objects.equals(nickName, user.getNickName()) &&
                Objects.equals(gender, Integer.valueOf( user.getGender() )) &&
                Objects.equals(language, user.getLanguage()) &&
                Objects.equals(city, user.getCity()) &&
                Objects.equals(province, user.getProvince()) &&
                Objects.equals(country, user.getCountry()) &&
                Objects.equals(avatarUrl, user.getAvatarUrl());
    }

    @Override
    public int hashCode() {
        return Objects.hash(openid, unionid, nickName, gender, language, city, province, country, avatarUrl);
    }
}
